//
//  ViewController.m
//  28_UIViewAnimation(2)
//
//  Created by 徐昊 on 16/8/22.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "ViewController.h"
#import "UIView+Frame.h"
@interface ViewController ()
@property (nonatomic, strong) UIView *animationView;
@property (nonatomic, strong) UIButton *animationButton;
@property (nonatomic ,strong) UIButton *animationButton2;
@end

@implementation ViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    _animationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
    [self.view addSubview:_animationView];
    _animationView.backgroundColor = [UIColor cyanColor];
    /**
     * 参数1:
     * 参数2:
     * 参数3: 0.0~1.0 数值越小, 阻力越小, 数值越大, 阻力越大
     * 参数4: 速度
     * 参数5: 选项
     */
    [UIView animateWithDuration:5 delay:0 usingSpringWithDamping:1.0f initialSpringVelocity:6.0f options:UIViewAnimationOptionRepeat animations:^{
        _animationView.h_width = 100;
        _animationView.h_height = 300;
        _animationView.backgroundColor = [UIColor yellowColor];
        
    } completion:^(BOOL finished) {
        NSLog(@"动画完成");
        
    }];
    _animationButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _animationButton.frame = CGRectMake(100, 200, 100, 200);
    _animationButton.backgroundColor = [UIColor redColor];
    [self.view addSubview:_animationButton];
    [_animationButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    _animationButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
    _animationButton2.frame = CGRectMake(100, 400, 100, 200);
    _animationButton2.backgroundColor = [UIColor greenColor];
    [self.view addSubview:_animationButton2];
    
    
}
- (void)buttonClicked:(UIButton *)button {
    /** 
     * 参数1: 需要执行动画的View
     * 参数2: 持续时间
     * 参数3: 动画效果
     * 参数4: 动画结束后的操作
     */
//    [UIView transitionWithView:_animationView duration:5 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
//        _animationView.h_height = 100;
//    } completion:^(BOOL finished) {
//        // 动画可以嵌套动画
//        [UIView animateWithDuration:0.5 animations:^{
//            
//            _animationView.h_height = 300;
//        }];
//    }];
    [UIView transitionFromView:_animationButton toView:_animationButton2 duration:5 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
        NSLog(@"动画完成");
        
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//    UIViewAnimationOptionLayoutSubviews//进行动画时布局子控件
//    UIViewAnimationOptionAllowUserInteraction//进行动画时允许用户交互
//    UIViewAnimationOptionBeginFromCurrentState//从当前状态开始动画
//    UIViewAnimationOptionRepeat//无限重复执行动画
//    UIViewAnimationOptionAutoreverse//执行动画回路
//    UIViewAnimationOptionOverrideInheritedDuration//忽略嵌套动画的执行时间设置
//    UIViewAnimationOptionOverrideInheritedCurve//忽略嵌套动画的曲线设置
//    UIViewAnimationOptionAllowAnimatedContent//转场：进行动画时重绘视图
//    UIViewAnimationOptionShowHideTransitionViews//转场：移除（添加和移除图层的）动画效果
//    UIViewAnimationOptionOverrideInheritedOptions//不继承父动画设置
//    UIViewAnimationOptionCurveEaseInOut//时间曲线，慢进慢出（默认值）
//    UIViewAnimationOptionCurveEaseIn//时间曲线，慢进
//    UIViewAnimationOptionCurveEaseOut//时间曲线，慢出
//    UIViewAnimationOptionCurveLinear//时间曲线，匀速
//    UIViewAnimationOptionTransitionNone//转场，不使用动画
//    UIViewAnimationOptionTransitionFlipFromLeft//转场，从左向右旋转翻页
//    UIViewAnimationOptionTransitionFlipFromRight//转场，从右向左旋转翻页
//    UIViewAnimationOptionTransitionCurlUp//转场，下往上卷曲翻页
//    UIViewAnimationOptionTransitionCurlDown//转场，从上往下卷曲翻页
//    UIViewAnimationOptionTransitionCrossDissolve//转场，交叉消失和出现
//    UIViewAnimationOptionTransitionFlipFromTop//转场，从上向下旋转翻页
//    UIViewAnimationOptionTransitionFlipFromBottom//转场，从下向上旋转翻页
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
